package com.ideal.controller;

import java.util.List;

import com.ideal.dto.ResultDto;
import com.ideal.dto.config.req.SysTreeDictReqDto;
import com.ideal.enums.GlobalExceptionEnum;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import com.ideal.model.SysTreeDict;
import com.ideal.service.ISysTreeDictService;

/**
 * 树形结构字典Controller
 *
 * @author ruoyi
 * @date 2022-07-21
 */
@Controller
@RequestMapping("/api/dict")
public class SysTreeDictController
{
    @Autowired
    private ISysTreeDictService sysTreeDictService;

    /**
     * 查询树形结构字典列表
     */
    @ResponseBody
    @RequestMapping(value = "/page",method = RequestMethod.GET)
    public ResultDto page(SysTreeDictReqDto sysTreeDictReqDto)
    {
        return ResultDto.success( sysTreeDictService.page(sysTreeDictReqDto));
    }

    /**
     * 获取树形结构字典详细信息
     */
    @ResponseBody
    @RequestMapping(value = "detail/{dictId}",method = RequestMethod.GET)
    public ResultDto getInfo(@PathVariable("dictId") Long dictId)
    {
        return ResultDto.success(sysTreeDictService.selectSysTreeDictByDictId(dictId));
    }

    /**
     * 新增树形结构字典
     */
    @ResponseBody
    @RequestMapping(value = "save",method = RequestMethod.POST)
    public ResultDto add(@RequestBody SysTreeDict sysTreeDict)
    {
        return ResultDto.success(sysTreeDictService.insertSysTreeDict(sysTreeDict));
    }

    /**
     * 修改树形结构字典
     */
    @ResponseBody
    @RequestMapping(value = "update",method = RequestMethod.POST)
    public ResultDto edit(@RequestBody SysTreeDict sysTreeDict)
    {
        return ResultDto.success(sysTreeDictService.updateSysTreeDict(sysTreeDict));
    }

    /**
     * 删除树形结构字典
     */
    @ResponseBody
    @RequestMapping(value = "remove/{dictId}",method = RequestMethod.GET)
    public ResultDto remove(@PathVariable("dictId") Long dictId)
    {

        return ResultDto.success(sysTreeDictService.deleteSysTreeDictByDictIds(dictId));
    }

    /**
     * 根据字典值查找子字典
     * @param dictValue
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "dictChildDetail/{dictValue}",method = RequestMethod.GET)
    public ResultDto dictChildDetail(@PathVariable("dictValue")String dictValue){
        return ResultDto.success(sysTreeDictService.dictChildDetail(dictValue));
    }

}
